import glob
import os
import cv2 as cv
import numpy as np
from PyCmpltrtok.common import sep

glob_str = '/home/asuspei/large_data/DL1/_many_files/cifar-10_pngs/cifar/test/9*_ship.png'
out_dir = '/home/asuspei/large_data/DL1/_many_files/cifar-10_pngs/clipped'

sep(glob_str)
paths = glob.glob(glob_str)
for path in paths:
    dir, base = os.path.split(path)
    main, ext = os.path.splitext(base)
    sep(path)
    img = cv.imread(path, cv.IMREAD_COLOR)
    H, W, C = img.shape

    # new = np.zeros([H * 2, W * 2, C], dtype=np.uint8)
    # new[H//2:H//2*3, W//2:W//2*3] = img
    # dest_path = os.path.join(out_dir, f'{main}.center{ext}')

    new = np.zeros([H + 4, W + 4, C], dtype=np.uint8)
    new[2:H + 2, 2:W + 2] = img
    dest_path = os.path.join(out_dir, f'{main}.center.s{ext}')

    res = cv.imwrite(dest_path, new)
    print(f'Written to {dest_path}, {res}')

sep('All over')
